﻿
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

Console.Title = "LuckyColaAI助手";

HttpClient client = new HttpClient();
RequestInfo info = new RequestInfo()
{
    appKey = "659f856dc7c5dfb046890dcf",
    uid = "t2SHxZ1704953175520467aTuoXpF",
};

Console.WriteLine("请输入你的问题！(按Ctrl+C可退出)");

await Task.Run(async () =>
{
    while (true)
    {
        var read = Console.ReadLine();

        if (!string.IsNullOrEmpty(read))
        {
            Console.Clear();

            info.ques = read;

            var content = new StringContent(JsonSerializer.Serialize(info), Encoding.UTF8);
            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            // 发送POST请求并获取响应
            HttpResponseMessage response = await client.PostAsync("https://luckycola.com.cn/ai/openwxyy", content);
            response.EnsureSuccessStatusCode();

            // 获取响应数据并输出到控制台
            string responseBody = await response.Content.ReadAsStringAsync();
            var responseInfo= JsonSerializer.Deserialize<ResponseInfo>(responseBody);

            await Console.Out.WriteLineAsync(responseInfo.data.result);
            await Console.Out.WriteLineAsync("--------------------------------");
            await Console.Out.WriteLineAsync($"剩余条数:{responseInfo.data.countMsg}");
            await Console.Out.WriteLineAsync("--------------------------------");

            await Console.Out.WriteLineAsync("请输入你的问题！(按Ctrl+C可退出)");
        }

    }

});

Console.ReadKey();

public class RequestInfo
{
    public string appKey { get; set; }
    public string ques { get; set; }
    public string uid { get; set; }

    public int isLongChat { get; set; } = 0;
}


public class ResponseInfo
{
    public int code { get; set; }
    public string msg { get; set; }
    public Data data { get; set; }
}

public class Data
{
    public string result { get; set; }
    public string countMsg { get; set; }
    public int longChat { get; set; }
}
